import 'package:flutter/material.dart';
import 'package:flutter_app/counter/counter_native_connect.dart';
import 'package:flutter_app/stateLearn/click_txt.dart';
import 'package:flutter_app/utils/log_util.dart';
import 'package:get/get.dart';

///author: create by SunJH
///时间: 2021/12/17 0017
///邮箱: 965989158@qq.com
///描述: flutter与Android原生通讯测试
///

class NativeConnect extends GetView<CounterNativeConnect> {
  const NativeConnect({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Get.put(CounterNativeConnect());
    return Scaffold(
      body: ListView(
        children: [
          Obx(() => Text(controller.printInfoResult.value)),
          Obx(() => Text(controller.fromNativeData.value)),
          ClickTxt(
            info: "发消息到android",onPressed: (){
                controller.sendMessageToAndroid('flutter跨平台通讯测试');
          },
          ),
          ClickTxt(
            info: "发送原生打印信息",onPressed: (){
                controller.nativePrintInfo('here is flutter ');
          },
          ),
          ClickTxt(
            info: "发送原生打印信息",onPressed: (){
            Get.defaultDialog(title: "apk下载",
              radius: 6,
              contentPadding:const EdgeInsets.all(10),
              ///返回值决定点击键盘返回按钮是否能关闭弹窗
              onWillPop: ()async{
              return true;
              },
              ///是否能点击弹窗外部关闭弹窗
              barrierDismissible: false,
              actions: [Container(child: ClickTxt(info: "取消",onPressed: (){
                  Get.back();
              },style: TextStyle(fontSize: 16,color: Colors.red.shade300),),alignment: Alignment.centerRight,)],
              content: Padding(
                padding: const EdgeInsets.only(top:10),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: const [
                    Text("当前进度"),
                    SizedBox(height: 10,),
                    LinearProgressIndicator(
                      value: 0.99,
                      backgroundColor: Colors.red,
                      color: Colors.orange,
                    ),
                  ],
                ),
              ),
              //弹窗关闭会回调该事件
            ).then((value) => LogUtil.logI("dialog关闭"));
          },
          ),
        ],
      ),
    );
  }
}
